<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/21
 * Time: 19:27
 */

namespace WebApp\lib\util;


use Swoole\Table;

class Set
{
    /**
     * @var Table
     */
    private $table;

    public function __construct($line_num)
    {
        $this->table = new Table($line_num);
        $this->table->column('val', Table::TYPE_INT, 1);
        $this->table->create();
    }

    public function add($key)
    {
        $this->table->set((string)$key, [
            'val'=> 1
        ]);
    }

    public function remove($key)
    {
        $this->table->del((string)$key);
    }

    public function exist($key)
    {
        return $this->table->exist((string)$key);
    }

    public function set($key, $val) {
        $this->table->set((string)$key, [
            'val'=> $val
        ]);
    }

    public function get($key) {
        $row = $this->table->get((string)$key);
        return $row['val'];
    }
}